#!/usr/bin/env python
import os
import sys
sys.path.append( os.path.join(os.getcwd(), 'keg_modules') )
#sys.path.append( os.path.join(os.getcwd(), 'keg_modules') )


import config
import web.database

### Setup a database connection
##connection = web.database.connect(
##    adapter = config.PYWEB_DB_ADAPTER, 
##    database = config.PYWEB_DB,
##    user = config.PYWEB_DB_USERNAME,
##    password = config.PYWEB_DB_PASSWD,
##    #autoCreate = 1,
##)
##cursor = connection.cursor() 
##
##import web.environment
##driver = web.environment.driver(
##    name= 'salestracker',
##    storage = 'database',
##    cursor=cursor,
##)
##
##if not driver.completeEnvironment():
##    driver.removeEnvironment(ignoreErrors=True)
##    driver.createEnvironment()
##    print "Environment created"
##else:
##    print "Environment already complete"
##connection.commit() # Save changes
##connection.close() # Close the connection


import web, web.database

# Setup a database connection
connection = web.database.connect(
    adapter="mysql", 
    database="sales",
    user="root",
    prepend="sales",    
)
cursor = connection.cursor() 

# Obtain Auth objects
import web.auth
from web.errors import AuthError
admin = web.auth.admin('database', cursor=cursor)

# Setup the environment (destroying the existing environment)
admin.removeAuthEnvironment(ignoreErrors=True)
admin.createAuthEnvironment()
